﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarCrash.Application.Drawing.entities.Forms
{
    public partial class RoadDialog : Form
    {
        private RoadLine roadline;
        //private PavementL pavementl;
        //private PavementR pavementr;

        public RoadDialog(RoadLine roadline)
        {
            InitializeComponent();
            this.roadline = roadline;
            //textBox1.Text = roadline.Length.ToString;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                textBox2.ReadOnly = true;
            else
                textBox2.ReadOnly = false;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
                textBox4.ReadOnly = false;
            else
                textBox4.ReadOnly = true;
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                textBox3.ReadOnly = false;
            else
                textBox3.ReadOnly = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int length;
            if (Int32.TryParse(textBox1.Text, out length))
                roadline.Length = length;
        }

        private void Submit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void RoadDialog_Load(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            int length;
            int wigthr;
            int wigthl;
            int wigth_line1;
            int wigth_line2;
            if (checkBox2.Checked)
            {
                if (checkBox3.Checked)
                {
                    if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox3.Text, out wigthr)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthl = wigthl;
                        roadline.Wigthr = wigthr;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 3;
                    }
                }
                else if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthl = wigthl;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 1;
                    }
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            int length;
            int wigthr;
            int wigthl;
            int wigth_line1;
            int wigth_line2;
            if (checkBox3.Checked)
            {
                if (checkBox2.Checked)
                {
                    if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox3.Text, out wigthr)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthr = wigthr;
                        roadline.Wigthl = wigthl;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 3;
                    }
                }
                else if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox3.Text, out wigthr)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthr = wigthr;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 2;
                    }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i;
            for (i = 0; i < 5; i++)
            {
               // comboBox1.Items.Add(str);
            }
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            int length;
            int wigthr;
            int wigthl;
            int wigth_line1;
            int wigth_line2;
            if (checkBox2.Checked)
            {
                if (checkBox3.Checked)
                {
                    if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox3.Text, out wigthr)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthl = wigthl;
                        roadline.Wigthr = wigthr;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 3;
                    }
                }
                else if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                {
                    roadline.Length = length;
                    roadline.Wigthl = wigthl;
                    roadline.Wigth_line1 = wigth_line1;
                    roadline.Wigth_line2 = wigth_line2;
                    roadline.Fg = 1;
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //1_Сплошная
            //2_Прерывистая
            if (comboBox2.Text == "2_Прерывистая")
            {
                roadline.Rg = 1;
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            int length;
            int wigthr;
            int wigthl;
            int wigth_line1;
            int wigth_line2;
            if (checkBox2.Checked)
            {
                if (checkBox3.Checked)
                {
                    if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox3.Text, out wigthr)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                    {
                        roadline.Length = length;
                        roadline.Wigthl = wigthl;
                        roadline.Wigthr = wigthr;
                        roadline.Wigth_line1 = wigth_line1;
                        roadline.Wigth_line2 = wigth_line2;
                        roadline.Fg = 3;
                    }
                }
                else if ((Int32.TryParse(textBox1.Text, out length)) && (Int32.TryParse(textBox4.Text, out wigthl)) && (Int32.TryParse(textBox5.Text, out wigth_line1)) && (Int32.TryParse(textBox6.Text, out wigth_line2)))
                {
                    roadline.Length = length;
                    roadline.Wigthl = wigthl;
                    roadline.Wigth_line1 = wigth_line1;
                    roadline.Wigth_line2 = wigth_line2;
                    roadline.Fg = 1;
                }
            }
        }

    }
}
